package com.note.servlet.note;

import com.note.service.note.noteService;
import com.note.service.note.noteServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class editNote extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String title = req.getParameter("title");
        String content = req.getParameter("content");
        int kind = Integer.parseInt(req.getParameter("kind"));
        int noteId = Integer.parseInt(req.getParameter("noteid"));
        noteService update = new noteServiceImpl();
        boolean b = update.updateNote(title, content, kind, noteId);
        if(b){
            resp.sendRedirect(req.getContextPath()+"/noteShow");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
